import 'package:flutter_vant/component/navBar.dart';
import 'package:flutter_vant/main.dart';
import 'package:flutter/material.dart';

class HookView extends HookWidget {
  final double width;
  final double height;
  final List<Widget> children;
  final Widget? child;
  final dynamic backgroundColor;
  final String title;
  HookView(
      {Key? key,
      this.width = 360,
      this.height = 640,
      this.children = const [],
      this.child,
      this.backgroundColor = 'rgb(247,248,250)',
      this.title = ''})
      : super(key: key);

  getStyle() {
    return {
      'main': {
        CssRule.width: double.infinity,
        CssRule.height: double.infinity,
        CssRule.overflowY: 'scroll',
        CssRule.flexDirection: 'col',
        CssRule.padding: 10,
      }
    };
  }

  Widget renderChildView() {
    if (children.length > 0) {
      return Frame(
        styles: getStyle()['main'],
        children: this.children,
      );
    } else {
      return child!;
    }
  }

  renderView() {
    return SafeArea(child: renderChildView());
  }

  renderAppBar() {
    if (title.isNotEmpty) {
      return VanNavBar(
        title: title,
      );
    } else {
      return null;
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: renderAppBar(),
        backgroundColor: HexColor(backgroundColor),
        body: this.renderView());
  }
}
